package com.tcredit.spider.web.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tcredit.spider.web.dao.UserDao;
import com.tcredit.spider.web.model.User;

@Service
@Transactional// mybatis事物控制3/3 (事物控制注解)
public class UserService {

	@Autowired
	private UserDao userDao;

	/**
	 * 新增
	 */
	public int add(String name) {
		User u = new User();
		u.setName(name);
		userDao.add(u);
		return u.getId();
	}
	
	/**
	 * 修改
	 */
	public int update(int id) {
		return userDao.update(id);
	}
	
	/**
	 * 测试回滚
	 */
	public int rollback(int id, String name){
		userDao.update(id);
		
		User u = new User();
		u.setName(name);
		userDao.add(u);

		if(1==1){
			throw new RuntimeException("123");
		}
		
		return 0;
	}

	/**
	 * 查询所有用户
	 */
	public List<User> getAll() {
		return userDao.getAllList();
	}

}
